package com.example.email.controller;

import com.example.common.ResultMessage;
import com.example.email.service.EmailService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author kangshuai
 */
@RestController
@RequestMapping("email")
public class EmailController {

    @Resource
    protected EmailService emailService;

    /**
     * 发送邮件验证码
     *
     * @param email
     * @param code
     * @return
     */
    @GetMapping(value = "send", produces = {"application/json;charset=UTF-8"})
    public ResultMessage<Boolean> sendEmail(@RequestParam("email") String email, @RequestParam("code") String code) {
        boolean res = emailService.sendEmail(email, code);

        if (res == true) {
            return ResultMessage.success(true);
        } else {
            return ResultMessage.error("邮件发送失败", false);
        }
    }
}
